package com.cloudsigns.factorymanager2.project.activity;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.cloudsigns.factorymanager2.R;
import com.cloudsigns.factorymanager2.project.adapter.ProductInformationAdapter;
import com.cloudsigns.factorymanager2.project.bean.ProductBean;
import com.cloudsigns.factorymanager2.project.utils.ConstantUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * 竣工评价
 * Created by tony on 2017/12/20.
 */

public class CompletionOfEvaluationActivity extends Activity implements View.OnClickListener {
    private RelativeLayout rl_right;
    private ImageView img_right;
    private ImageView img_back;
    private TextView tv_title;
    private ImageView img_completion_of_evaluation;
    private TextView btn_confirm_evaluation;
    private ListView lv;
    private ProductInformationAdapter adapter;
    private List<ProductBean> productBeanList = new ArrayList<>();
    private final String TAG = "CompletionOfEvaluationActivity";

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);//去掉标题栏
        // 沉浸式状态栏
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            Window window = getWindow();
            window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
                    );
            window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN

                    | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            window.setStatusBarColor(Color.TRANSPARENT);

        } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        }
        setContentView(R.layout.layout_completion_of_evaluation);

        init();
    }

    private void init() {
        img_back = findViewById(R.id.img_back);
        rl_right = findViewById(R.id.rl_right);
        img_right = findViewById(R.id.img_right);
        tv_title = findViewById(R.id.tv_title);
        img_completion_of_evaluation = findViewById(R.id.img_completion_of_evaluation);
        btn_confirm_evaluation = findViewById(R.id.btn_confirm_evaluation);
        lv = findViewById(R.id.lv);


        tv_title.setText("竣工评价");
        rl_right.setVisibility(View.VISIBLE);
        img_back.setVisibility(View.VISIBLE);
        img_right.setBackgroundResource(R.mipmap.icon_msg);
        rl_right.setOnClickListener(this);
        img_back.setOnClickListener(this);
        img_completion_of_evaluation.setOnClickListener(this);
        btn_confirm_evaluation.setOnClickListener(this);

        adapter = new ProductInformationAdapter(this, TAG);
        adapter.setData(productBeanList);
//        lv.setAdapter(adapter);
    }

    private void confirmEvaluation() {
        Toast.makeText(this, "竣工成功", Toast.LENGTH_SHORT).show();
        finish();
    }

    @Override
    public void onClick(View view) {
        Intent mIntent;
        switch (view.getId()) {
            case R.id.img_back:
                finish();
                break;
            case R.id.btn_confirm_evaluation:  //确认竣工
                confirmEvaluation();
                break;
            case R.id.img_completion_of_evaluation: //添加竣工评价
                mIntent = new Intent(CompletionOfEvaluationActivity.this, AddCompletionOfEvaluationActivity.class);
                startActivityForResult(mIntent, ConstantUtil.ADD_COMPLETION_OF_EVALUATION);
                break;
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        switch (requestCode) {
            case ConstantUtil.ADD_COMPLETION_OF_EVALUATION: //添加产品信息
                if (data != null) {
                    boolean bool = data.getBooleanExtra(ConstantUtil.COMPLETION_OF_EVALUATION_BEAN, false);
                    if (bool) {
//                        productBeanList.add(new ProductBean(null, 0, null, null, 0, null));
//                        adapter.setData(productBeanList);
//                        adapter.notifyDataSetChanged();
                    }

                }
                break;
        }
        super.onActivityResult(requestCode, resultCode, data);
    }
}
